﻿namespace Vboot.Core.Module.Bpm;

public class BpmTaskHistService : ITransient
{
    public async Task<BpmTaskHist> CreateTask(BpmTaskMain mainTask)
    {
        BpmTaskHist histTask = new BpmTaskHist();
        histTask.id = mainTask.id;
        histTask.proid = mainTask.proid;
        histTask.state = "20";
        histTask.exman = mainTask.exman;
        histTask.nodid = mainTask.nodid;
        histTask.type = "1";
        await _repo.InsertAsync(histTask);
        return histTask;
    }

    public async Task<BpmTaskHist> FindOne(string id)
    {
        return await _repo.GetSingleAsync(t => t.id == id);
    }

    public async Task Delete(string id)
    {
        await _repo.Context.Deleteable<BpmTaskHist>().Where(it => it.id == id).ExecuteCommandAsync();
    }

    public async Task Update(BpmTaskHist hist)
    {
        await _repo.Context.Updateable(hist).ExecuteCommandAsync();
    }

    private readonly SqlSugarRepository<BpmTaskHist> _repo;

    public BpmTaskHistService(SqlSugarRepository<BpmTaskHist> repo)
    {
        _repo = repo;
    }
}